home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1997 #3
/
Amiga Plus CD - 1997 - No. 03.iso
/
pd
/
programmierung
/
alienbreed3d2_src
/
amos
/
fibcomp.amos
/
fibcomp.amosSourceCode
Wrap
AMOS Source Code
|
1997-01-31
|
2KB
|
97 lines
'this program will compact an 8 bit sample using fibonacci compression
Dim F(15),DIFF(512)
F(0)=-34
F(1)=-21
F(2)=-13
F(3)=-8
F(4)=-5
F(5)=-3
F(6)=-2
F(7)=-1
F(8)=0
F(9)=1
F(10)=2
F(11)=3
F(12)=5
F(13)=8
F(14)=13
F(15)=21
For N=-256 To 256
D=Abs(F(0)-N) : F=0
For FF=1 To 15
If Abs(F(FF)-N)<D
D=Abs(F(FF)-N)
F=FF
End If
Next
DIFF(N+256)=F
Next
Repeat
F$=Fsel$("","","Please select a sample to compress")
If Exist(F$)
Reserve As Work 10, Extension_18_0294(F$)
Reserve As Work 11,Length(10)
Bload F$,10
If Instr(F$,"/")
D$=Left$(F$, Extension_18_0086(F$,"/"))
FF$=Mid$(F$, Extension_18_0086(F$,"/")+1)
Else
D$=Left$(F$, Extension_18_0086(F$,":"))
FF$=Mid$(F$, Extension_18_0086(F$,":")+1)
End If
If Peek$(Start(10),4)="FORM"
A=Hunt(Start(10) To Start(10)+Length(10),"BODY")+8
Else
A=Start(10)
End If
B=Start(11)
'store initial value
MYPEEK[A] : V=Param : Inc A
Poke B,V : Inc B
Repeat
MYPEEK[A] : NV=Param : Inc A
DV=Min(Max(0,256+NV-V),512)
Poke B,DIFF(DV) : Inc B
V=V+F(DIFF(DV))
Until A=Start(10)+Length(10)
Reserve As Chip Work 12,Length(11)
'decompress the sample back into a bank to make sure it works
B=Start(12)
MYPEEK[Start(11)] : V=Param
For A=Start(11)+1 To Start(11)+Length(11)-1
Poke B,V : Inc B
MYPEEK[A] : D=Param
V=V+F(D)
Next
Sam Raw 3,Start(12),Length(12),8000
'meanwhile, compress the data down into two nibbles per byte
Reserve As Work 13,Length(11)+80
B=Start(13)
Poke$ B,"CSFX" : Add B,4
Loke B,Length(12) : Add B,4
Poke B,Peek(Start(11)) : Inc B
For A=Start(11)+1 To Start(11)+Length(11)-1 Step 2
D1=Peek(A)*16
D2=Peek(A+1)
D=D1 or D2
Poke B,D : Inc B
Next
NF$=FF$+".fib"
Bsave NF$,Start(13) To B
Erase 10
Erase 11
End If
Until F$=""
Edit
Procedure MYPEEK[A]
D=Peek(A)
If Btst(7,D)
D=D or $FFFFFF00
End If
End Proc[D]